<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Simply tell Laravel the HTTP verbs and URIs it should respond to. It is a
| breeze to setup your application using Laravel's RESTful routing and it
| is perfectly suited for building large applications and simple APIs.
|
| Let's respond to a simple GET request to http://example.com/hello:
|
|		Route::get('hello', function()
|		{
|			return 'Hello World!';
|		});
|
| You can even respond to more than one URI:
|
|		Route::post(array('hello', 'world'), function()
|		{
|			return 'Hello World!';
|		});
|
| It's easy to allow URI wildcards using (:num) or (:any):
|
|		Route::put('hello/(:any)', function($name)
|		{
|			return "Welcome, $name.";
|		});
|
*/

/*Route::filter('auth', function()
{
    if (Auth::guest()) return Redirect::to('login');

    if (Auth::user()->role_id == 1) {
        return Redirect::to('admin');
    }

});*/




Route::filter('role', function()
{
    if (Auth::guest()){
        return Redirect::to('/login');
    }
});





Route::get('/', 'Site::home@index');

Route::get('/sitemap', 'Admin::utility.sitemap@index');
Route::get('/rss', 'Admin::utility.sitemap@rss');
Route::get('/rdf', 'Admin::utility.sitemap@rdf');
Route::get('/text', 'Admin::utility.sitemap@text');
Route::get('/html', 'Admin::utility.sitemap@html');

//LOGIN

Route::get('login','Member::Register@index');
Route::post('login', 'Member::login@in');
Route::get('logout', 'Site::login@out');

//Autocomplete routing

Route::get('category/all','Site::browse@all');
Route::get('category/widget/filter/(:any)','Category::widget.filter@index');

Route::get('location/all','Location::widget.popular@all');


Route::get('comments/all','Comments::index@all');

Route::get('autocomplete/category/(:any)', 'Site::autocomplete@category');
Route::get('autocomplete/location/(:any)', 'Site::autocomplete@location');
Route::get('autocomplete/business/(:any)', 'Site::autocomplete@business');
Route::get('autocomplete/child_category/(:any)', 'Site::autocomplete@child_category');
Route::get('autocomplete/child_key/(:any)', 'Site::autocomplete@child_key');
Route::get('autocomplete/products/(:any)','Products::autocomplete@products');

//SEARCH
Route::post('/search/services', 'Site::search@services');
Route::post('/search/business', 'Site::search@business');
Route::post('/search/products','Products::home@products');
Route::post('/search/requirements','Products::home@requirements');




Route::get('business/(:any)/(:any)','Site::search@business');
Route::get('page/(:any)','Site::widget.footer@pages');

Route::get('location/all/(:any)','Location::widget.popular@location');
Route::get('location/clear','Location::home@clear_location');

Route::get('phpinfo', 'Site::home@phpinfo');
Route::get('(:any)', 'Site::browse@location');
Route::get('(:any)/(:any)', 'Site::browse@category');

//PROFILE
Route::get('(:any)/(:any)/(:any)/(:num)', 'Site::profile@index');
Route::post('site/profile/enquiry', 'Site::profile@enquiry');
Route::post('site/profile/inc', 'Site::profile@inc');

Route::post('site/profile/claim','Site::profile@claim');


//Route::post('products/requirement/add','Products::widget.requirement@requirement');



/*
|--------------------------------------------------------------------------
| Application 404 & 500 Error Handlers
|--------------------------------------------------------------------------
|
| To centralize and simplify 404 handling, Laravel uses an awesome event
| system to retrieve the response. Feel free to modify this function to
| your tastes and the needs of your application.
|
| Similarly, we use an event to handle the display of 500 level errors
| within the application. These errors are fired when there is an
| uncaught exception thrown in the application.
|
*/

Event::listen('404', function()
{
    return Response::error('404');
});

Event::listen('500', function()
{
    return Response::error('500');
});

/*
|--------------------------------------------------------------------------
| Route Filters
|--------------------------------------------------------------------------
|
| Filters provide a convenient method for attaching functionality to your
| routes. The built-in before and after filters are called before and
| after every request to your application, and you may even create
| other filters that can be attached to individual routes.
|
| Let's walk through an example...
|
| First, define a filter:
|
|		Route::filter('filter', function()
|		{
|			return 'Filtered!';
|		});
|
| Next, attach the filter to a route:
|
|		Route::get('/', array('before' => 'filter', function()
|		{
|			return 'Hello World!';
|		}));
|
*/

Route::filter('before', function()
{
    // Do stuff before every request to your application...
});

Route::filter('after', function($response)
{
    // Do stuff after every request to your application...
});

Route::filter('csrf', function()
{
    if (Request::forged()) return Response::error('500');
});

Route::filter('auth', function()
{
    if (Auth::guest()) return Redirect::to('login');
});